//Shirasu Azusa 2024.5
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;  
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} 
  return x*w;
}

const int N=4e5+5,base=1e9+7;
int n,q,p,a[N],b[N],c[N],r[N],k,palin,sc1,sc21,sf,qa[N];
ull h1[N],h2[N],w[N],f[N];
unordered_map<int,int> id,c1,c2[3],ans;
vi d[N],gg;

ull hsh1(int l,int r) {
  return h1[r]-h1[l-1]*w[r-l+1];
}
ull hsh2(int l,int r) {
  return h2[l]-h2[r+1]*w[r-l+1];
}

int manacher(int n,int *s) {
  static int t[N],f[N]; int m=0; t[++m]=base,t[0]=base+1;
  rep(i,1,n) t[++m]=s[i], t[++m]=base;
  for(int p=0,r=0,i=1;i<=m;i++) {
    if(r>=i) f[i]=min(f[2*p-i],r-i+1);
    for(;t[i-f[i]]==t[i+f[i]];f[i]++);
    if(i+f[i]-1>=r) r=i+f[i]-1, p=i;
  } int res=0; rep(i,1,m) res+=f[i]/2; return res;
}

void brute() {
  rep(i,1,q) {
    int ans=0, op=read(), A=-1, B=-1;
    if(op==1) A=read(); else B=read();
    rep(xa,0,p-1) rep(xb,0,p-1) {
      if(A!=-1&&A!=xa) continue;
      if(B!=-1&&B!=xb) continue;
      rep(l,1,n) rep(r,l,n) {
        bool flag=1;
        rep(k,l,r) flag&=((a[k]*xa+xb)%p==a[l+r-k]);
        ans+=flag;
      }
    }
    printf("%lld\n",ans);
  }
}

signed main() {
  freopen("string.in","r",stdin);
  freopen("string.out","w",stdout); 
  n=read(), q=read(), p=read();
  rep(i,1,n) a[i]=read();
  if(n<=100&&q<=100&&p<=100) {
    brute(); return 0;
  }
  rep(i,1,n) b[i]=(a[i+1]-a[i]+p)%p;
  per(i,n,1) c[i]=(a[i]-a[i-1]+p)%p;
  for(int x=1;x*x<=p;x++) if(p%x==0) {
    gg.eb(x); if(p/x!=x) gg.eb(p);
  }
  sort(gg.begin(),gg.end()); k=gg.size();
  rep(i,1,k) r[i]=gg[i-1], id[r[i]]=i;
  rep(i,1,k) rep(j,1,i) if(r[i]%r[j]==0) d[i].eb(j);

  w[0]=1; rep(i,1,n) w[i]=w[i-1]*base;
  rep(i,1,n) h1[i]=h1[i-1]*base+b[i];
  per(i,n,1) h2[i]=h2[i+1]*base+c[i];
  rep(i,1,n-1) {
    int x=i, y=i+1, w=0;
    for(int l=0,r=min(x-1,n-y);l<=r;) {
      int mid=l+r>>1;
      if(hsh1(x-mid,x)==hsh2(y,y+mid)) w=mid, l=mid+1;
      else r=mid-1;
    }
    c1[(a[x]+a[y])%p]+=w+1, sc1+=w+1;
  }
  rep(i,1,n) {
    int l=i, r=i;
    while(r<=n&&a[r]==a[l]) r++; r--;
    int j1=0,j0=0;
    rep(k,1,r-l+1) {
      if(k&1) j1+=(r-l+1-k+1);
      else j0+=(r-l+1-k+1);
    }
    c2[1][a[l]]+=j1, sc21+=j1;
    c2[0][a[l]]+=j0;
    c2[2][a[l]]+=j0+j1;
    f[id[__gcd(a[l],p)]]+=(j0+j1), sf+=j0+j1;
    i=r;
  }
  palin=manacher(n,a);

    rep(i,1,q) {
      int op=read();
      if(op==1) {
        int a=read();   
        if(a==p-1) {
          printf("%lld\n",sc1+sc21);
        } else if(a*a%p==1) {
          printf("%lld\n",palin);
        } else {
          printf("%lld\n",sf);
        }
      } else {
        int b=read();
        int C1=c1[b];
        int C2=(b==0)*palin;
        int C3=0;
        int gg=__gcd(b,p);
        rep(j,1,k) if(gg%r[j]==0) C3+=f[j]*r[j];
        int D3=0;
        if(p&1) D3=c1[(p+1)/2*b%p];
        else if(b%2==0) D3=c1[b/2]+c1[b/2+p/2];
        printf("%lld\n",C1+C2+C3-D3);
      }
    }
    return 0;
}